#!/bin/bash
#
# Example script to create WebTrust Crypto Portal Tokens
#



if [ $# -ne 1 ]
then
  echo "Create token for Cloud Hosting"
  echo "Usage: `basename $0` url-to-encrypted-file "
  exit 1
fi

url=$1

# Check for ccrypt
if [ ! -f `which ccrypt` ]; then
 echo "ccrypt does not exist"
  exit 1
fi

## Read key
echo -n "File Key: "
 stty -echo
  read key
  echo
 stty echo
echo -n "File Key (again): "
 stty -echo
  read key2
  echo
 stty echo

# Verify Input
if [ "$key" != "$key2" ];
then
   echo "mismatch"
   exit 1
fi

echo -n "Should access be validated? [y/n]: "
 read validate
 if [[ $validate = [yY] ]];then
	echo -n "Enter Valid Email or IP: "
	read validate
 elif [[ $validate = [nN] ]];then
	validate="null"
 else
	echo "invalid"
	exit 1
 fi

echo -n "Who is this file from (ie, webmaster@domain.tld): "
 read from
echo -n "Short message to recipent: "
 read message
echo -n "Force download or try to embed? (0=download, mime-type=embed) ie, image/jpeg : "
 read mime


token=`pwgen -A -n 8 1`
echo "$validate" > $token
echo "$from" >> $token
echo "$message" >> $token
echo "$mime" >> $token
echo "$url" >> $token
echo "$key" >> $token

pw=`pwgen -B 10 1`
echo $pw | ccrypt -k - $token
echo "encrypted $token.cpt"
echo -n "Upload $token.cpt to webtru.st and give the user this token: "
echo -n "$token"
echo -n "$pw"
echo
